import { _decorator, Collider2D, Component, Contact2DType, Director, director, Node, view } from 'cc';
import { EventManager } from './manager/event';
import { GameConst } from './config/game-param';
const { ccclass, property } = _decorator;

@ccclass('Ground')
export class Ground extends Component {
    @property(Node) private ground: Node

    private _ctrl: boolean = false
    private speed: number = GameConst.MOVE_SPEED
    private _width: number
    
    start() {
        this._width = view.getVisibleSize().width
    }

    update(deltaTime: number) {
        if (!this._ctrl) return

        const distance = this.speed * deltaTime
        this.node.setPosition(this.node.position.x - distance, this.node.position.y)
        if (this.node.position.x < -this._width) {
            this.node.setPosition(this.node.position.x + this._width, this.node.position.y)
        }
    }

    startMove() {
        this._ctrl = true
    }

    stopMove() {
        this._ctrl = false
    }
}


